{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generate dataset for ALPACA\n",
    "\n",
    "## Use token from OpenAI to generate dataset for finetuning\n",
    "### You can get token from [here](https://beta.openai.com/docs/api-reference/authentication)\n",
    "### You can also use AI Studio and Cohere to generate dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "is_executing": true
    }
   },
   "outputs": [],
   "source": [
    "from xturing.datasets import InstructionDataset\n",
    "from xturing.model_apis.openai import Davinci"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# you can specify different model using engine parameter, default is davinci, you also can add strings\n",
    "# you can provide organization name with organization parameter\n",
    "engine = Davinci(\"your-api-key\")\n",
    "dataset = InstructionDataset.generate_dataset(engine=engine, path=\"./seed_tasks.jsonl\")\n",
    "\n",
    "# Alternatively, you can use Cohere to generate dataset\n",
    "\n",
    "# from xturing.model_apis.cohere import Medium\n",
    "#\n",
    "# engine = Medium(\"your-api-key\")\n",
    "\n",
    "# Alternatively, you can use AI21 to generate dataset\n",
    "\n",
    "# from xturing.model_apis.ai21 import J2Grande\n",
    "#\n",
    "# engine = J2Grande(\"your-api-key\")"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "from xturing.models import GPT2Lora\n",
    "\n",
    "model = GPT2Lora()"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# Finetune the model on generated dataset\n",
    "model.finetune(dataset=dataset)"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
